<template>
  <elm-page-bb>
    <el-form ref="model" :model="model" size="small" label-width="80px">
      <elm-row>
        <el-form-item label="编号" prop="sys_code_key">
          <el-input v-model="model.sys_code_key" disabled placeholder="自动生成无需填写"></el-input>
        </el-form-item>
        <el-form-item label="名称" prop="name" :rules="[{ required: true, message: '名称必须填写'}]">
          <el-input type="name" v-model="model.name"></el-input>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="类型">
          <el-select v-model="model.type" style="width:100%">
            <el-option label="自制" value="自制"></el-option>
            <el-option label="委外" value="委外"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上级">
          <elm-select-tree v-model="model.pid" url="/business/plm/product/craft/GetTree" path-url="/business/plm/product/craft/GetPath"></elm-select-tree>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="顺序" prop="sort" :rules="[{ required: true, message: '顺序必须填写'},{ type: 'number', message: '顺序必须为数字'}]">
          <el-input v-model.number="model.sort"></el-input>
        </el-form-item>
      </elm-row>
      <el-form-item label="备注">
        <el-input type="textarea" v-model="model.remark" :rows="2"></el-input>
      </el-form-item>
    </el-form>
    <template #bottom>
      <el-button type="success" size="small" @click="submit" model.>立即保存</el-button>
      <el-button size="small" @click="close">取消</el-button>
    </template>
  </elm-page-bb>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {
        pid: elm.dialog.request.pid,
        pd_code: elm.dialog.request.pd_code
      },
    }
  },
  created() {
    console.log(this.model);
  },
  methods: {
    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/plm/product/craft/Upsert', this.model);
      if (res == true) {
        this.close();
        this.v('保存成功。');
        this.request.callVue.treebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    }
  }
}
</script>

<style scoped>
</style>